

class KisConfigDictionaryController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        params.sort = params.sort ? params.sort : "orderflag" 
    	params.order = params.order ? params.order : "ASC"
        [ kisConfigDictionaryInstanceList: KisConfigDictionary.list( params ), kisConfigDictionaryInstanceTotal: KisConfigDictionary.count() ]
    }

    def show = {
        def kisConfigDictionaryInstance = KisConfigDictionary.get( params.id )

        if(!kisConfigDictionaryInstance) {
            flash.message = "KisConfigDictionary not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ kisConfigDictionaryInstance : kisConfigDictionaryInstance ] }
    }

    def delete = {
        def kisConfigDictionaryInstance = KisConfigDictionary.get( params.id )
        if(kisConfigDictionaryInstance) {
            try {
                kisConfigDictionaryInstance.delete(flush:true)
                flash.message = "KisConfigDictionary ${params.id} deleted"
                redirect(action:list)
            }
            catch(org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "KisConfigDictionary ${params.id} could not be deleted"
                redirect(action:show,id:params.id)
            }
        }
        else {
            flash.message = "KisConfigDictionary not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def kisConfigDictionaryInstance = KisConfigDictionary.get( params.id )

        if(!kisConfigDictionaryInstance) {
            flash.message = "KisConfigDictionary not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ kisConfigDictionaryInstance : kisConfigDictionaryInstance ]
        }
    }

    def update = {
        def kisConfigDictionaryInstance = KisConfigDictionary.get( params.id )
        if(kisConfigDictionaryInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(kisConfigDictionaryInstance.version > version) {
                    
                    kisConfigDictionaryInstance.errors.rejectValue("version", "kisConfigDictionary.optimistic.locking.failure", "Another user has updated this KisConfigDictionary while you were editing.")
                    render(view:'edit',model:[kisConfigDictionaryInstance:kisConfigDictionaryInstance])
                    return
                }
            }
            kisConfigDictionaryInstance.properties = params
            if(!kisConfigDictionaryInstance.hasErrors() && kisConfigDictionaryInstance.save()) {
                flash.message = "KisConfigDictionary ${params.id} updated"
                redirect(action:show,id:kisConfigDictionaryInstance.id)
            }
            else {
                render(view:'edit',model:[kisConfigDictionaryInstance:kisConfigDictionaryInstance])
            }
        }
        else {
            flash.message = "KisConfigDictionary not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def create = {
        def kisConfigDictionaryInstance = new KisConfigDictionary()
        kisConfigDictionaryInstance.properties = params
        return ['kisConfigDictionaryInstance':kisConfigDictionaryInstance]
    }

    def save = {
        def kisConfigDictionaryInstance = new KisConfigDictionary(params)
        if(!kisConfigDictionaryInstance.hasErrors() && kisConfigDictionaryInstance.save()) {
            flash.message = "KisConfigDictionary ${kisConfigDictionaryInstance.id} created"
            redirect(action:show,id:kisConfigDictionaryInstance.id)
        }
        else {
            render(view:'create',model:[kisConfigDictionaryInstance:kisConfigDictionaryInstance])
        }
    }
}
